package edu.neusoft.springhtmldemo.mapper;
import edu.neusoft.springhtmldemo.domain.UserManagement;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface UserManagementMapper {
    @Select("Select * FROM usermanagemententity WHERE userName='%'#{userName}'%' AND pswd='%'#{pswd}'%'")
    UserManagement login(UserManagement userManagement);
    UserManagement getUserByUserName(String username);

//    @Select("select * from usermanagemententity")
    @Select("SELECT ue.userId,ue.userName,ue.pswd,ur.roleId,ue.userPic,ue.dept,ue.telNum FROM usermanagemententity ue, userroleenum ur where ue.roleId=ur.id order by ue.userId")
    List<UserManagement> selectuserManagementAll();

    @Select("insert into usermanagemententity(userName,pswd,roleId,userPic,dept,telNum) value (#{userName},#{pswd},#{roleId},#{userPic},#{dept},#{telNum})")
    void addUserManagement(UserManagement userManagement);

    @Select("delete from usermanagemententity where userId in (#{userId})")
    void delUserManagement(Integer userId);


    @Select("update usermanagemententity set userName=#{userName},pswd=#{pswd},roleId=#{roleId},userPic=#{userPic},dept=#{dept},telNum=#{telNum} where userId=#{userId}")
    void updateUserManagement(UserManagement userManagement);

//    @Select("select * from usermanagemententity " +
//            "where(userName like '%' #{userName} '%' or #{userName} is null) " +
//            "or (dept like '%' #{dept} '%' or #{dept} is null)")
    @Select("select * from usermanagemententity where userName like '%' #{userName} '%' and dept like '%' #{dept} '%'")
    List<UserManagement> selectUserByUserNameAndDept(String userName,String dept);

    @Select("select * from usermanagemententity where userName=#{userName}")
    UserManagement selectUserByNameAndPwd(UserManagement userManagement);
}
